/**
 * <copyright>
 * </copyright>
 *

 */
package ms.unicorn.language.languagedef.impl;

import java.util.Collection;

import ms.unicorn.language.languagedef.LanguagedefPackage;
import ms.unicorn.language.languagedef.Parameter;
import ms.unicorn.language.languagedef.TagEntryDef;
import ms.unicorn.language.languagedef.XReferenceExpression;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.MinimalEObjectImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

import org.eclipse.xtext.xbase.XExpression;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Tag Entry Def</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link ms.unicorn.language.languagedef.impl.TagEntryDefImpl#getName <em>Name</em>}</li>
 *   <li>{@link ms.unicorn.language.languagedef.impl.TagEntryDefImpl#getParameters <em>Parameters</em>}</li>
 *   <li>{@link ms.unicorn.language.languagedef.impl.TagEntryDefImpl#isTypedEntry <em>Typed Entry</em>}</li>
 *   <li>{@link ms.unicorn.language.languagedef.impl.TagEntryDefImpl#getType <em>Type</em>}</li>
 *   <li>{@link ms.unicorn.language.languagedef.impl.TagEntryDefImpl#getValue <em>Value</em>}</li>
 *   <li>{@link ms.unicorn.language.languagedef.impl.TagEntryDefImpl#getRef <em>Ref</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class TagEntryDefImpl extends MinimalEObjectImpl.Container implements TagEntryDef
{
  /**
   * The default value of the '{@link #getName() <em>Name</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getName()
   * @generated
   * @ordered
   */
  protected static final String NAME_EDEFAULT = null;

  /**
   * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getName()
   * @generated
   * @ordered
   */
  protected String name = NAME_EDEFAULT;

  /**
   * The cached value of the '{@link #getParameters() <em>Parameters</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getParameters()
   * @generated
   * @ordered
   */
  protected EList<Parameter> parameters;

  /**
   * The default value of the '{@link #isTypedEntry() <em>Typed Entry</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #isTypedEntry()
   * @generated
   * @ordered
   */
  protected static final boolean TYPED_ENTRY_EDEFAULT = false;

  /**
   * The cached value of the '{@link #isTypedEntry() <em>Typed Entry</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #isTypedEntry()
   * @generated
   * @ordered
   */
  protected boolean typedEntry = TYPED_ENTRY_EDEFAULT;

  /**
   * The default value of the '{@link #getType() <em>Type</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getType()
   * @generated
   * @ordered
   */
  protected static final String TYPE_EDEFAULT = null;

  /**
   * The cached value of the '{@link #getType() <em>Type</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getType()
   * @generated
   * @ordered
   */
  protected String type = TYPE_EDEFAULT;

  /**
   * The cached value of the '{@link #getValue() <em>Value</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getValue()
   * @generated
   * @ordered
   */
  protected XExpression value;

  /**
   * The cached value of the '{@link #getRef() <em>Ref</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getRef()
   * @generated
   * @ordered
   */
  protected XReferenceExpression ref;

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  protected TagEntryDefImpl()
  {
    super();
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  protected EClass eStaticClass()
  {
    return LanguagedefPackage.Literals.TAG_ENTRY_DEF;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public String getName()
  {
    return name;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setName(String newName)
  {
    String oldName = name;
    name = newName;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, LanguagedefPackage.TAG_ENTRY_DEF__NAME, oldName, name));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<Parameter> getParameters()
  {
    if (parameters == null)
    {
      parameters = new EObjectContainmentEList<Parameter>(Parameter.class, this, LanguagedefPackage.TAG_ENTRY_DEF__PARAMETERS);
    }
    return parameters;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public boolean isTypedEntry()
  {
    return typedEntry;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setTypedEntry(boolean newTypedEntry)
  {
    boolean oldTypedEntry = typedEntry;
    typedEntry = newTypedEntry;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, LanguagedefPackage.TAG_ENTRY_DEF__TYPED_ENTRY, oldTypedEntry, typedEntry));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public String getType()
  {
    return type;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setType(String newType)
  {
    String oldType = type;
    type = newType;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, LanguagedefPackage.TAG_ENTRY_DEF__TYPE, oldType, type));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public XExpression getValue()
  {
    return value;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetValue(XExpression newValue, NotificationChain msgs)
  {
    XExpression oldValue = value;
    value = newValue;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, LanguagedefPackage.TAG_ENTRY_DEF__VALUE, oldValue, newValue);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setValue(XExpression newValue)
  {
    if (newValue != value)
    {
      NotificationChain msgs = null;
      if (value != null)
        msgs = ((InternalEObject)value).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - LanguagedefPackage.TAG_ENTRY_DEF__VALUE, null, msgs);
      if (newValue != null)
        msgs = ((InternalEObject)newValue).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - LanguagedefPackage.TAG_ENTRY_DEF__VALUE, null, msgs);
      msgs = basicSetValue(newValue, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, LanguagedefPackage.TAG_ENTRY_DEF__VALUE, newValue, newValue));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public XReferenceExpression getRef()
  {
    return ref;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetRef(XReferenceExpression newRef, NotificationChain msgs)
  {
    XReferenceExpression oldRef = ref;
    ref = newRef;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, LanguagedefPackage.TAG_ENTRY_DEF__REF, oldRef, newRef);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setRef(XReferenceExpression newRef)
  {
    if (newRef != ref)
    {
      NotificationChain msgs = null;
      if (ref != null)
        msgs = ((InternalEObject)ref).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - LanguagedefPackage.TAG_ENTRY_DEF__REF, null, msgs);
      if (newRef != null)
        msgs = ((InternalEObject)newRef).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - LanguagedefPackage.TAG_ENTRY_DEF__REF, null, msgs);
      msgs = basicSetRef(newRef, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, LanguagedefPackage.TAG_ENTRY_DEF__REF, newRef, newRef));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
  {
    switch (featureID)
    {
      case LanguagedefPackage.TAG_ENTRY_DEF__PARAMETERS:
        return ((InternalEList<?>)getParameters()).basicRemove(otherEnd, msgs);
      case LanguagedefPackage.TAG_ENTRY_DEF__VALUE:
        return basicSetValue(null, msgs);
      case LanguagedefPackage.TAG_ENTRY_DEF__REF:
        return basicSetRef(null, msgs);
    }
    return super.eInverseRemove(otherEnd, featureID, msgs);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public Object eGet(int featureID, boolean resolve, boolean coreType)
  {
    switch (featureID)
    {
      case LanguagedefPackage.TAG_ENTRY_DEF__NAME:
        return getName();
      case LanguagedefPackage.TAG_ENTRY_DEF__PARAMETERS:
        return getParameters();
      case LanguagedefPackage.TAG_ENTRY_DEF__TYPED_ENTRY:
        return isTypedEntry();
      case LanguagedefPackage.TAG_ENTRY_DEF__TYPE:
        return getType();
      case LanguagedefPackage.TAG_ENTRY_DEF__VALUE:
        return getValue();
      case LanguagedefPackage.TAG_ENTRY_DEF__REF:
        return getRef();
    }
    return super.eGet(featureID, resolve, coreType);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @SuppressWarnings("unchecked")
  @Override
  public void eSet(int featureID, Object newValue)
  {
    switch (featureID)
    {
      case LanguagedefPackage.TAG_ENTRY_DEF__NAME:
        setName((String)newValue);
        return;
      case LanguagedefPackage.TAG_ENTRY_DEF__PARAMETERS:
        getParameters().clear();
        getParameters().addAll((Collection<? extends Parameter>)newValue);
        return;
      case LanguagedefPackage.TAG_ENTRY_DEF__TYPED_ENTRY:
        setTypedEntry((Boolean)newValue);
        return;
      case LanguagedefPackage.TAG_ENTRY_DEF__TYPE:
        setType((String)newValue);
        return;
      case LanguagedefPackage.TAG_ENTRY_DEF__VALUE:
        setValue((XExpression)newValue);
        return;
      case LanguagedefPackage.TAG_ENTRY_DEF__REF:
        setRef((XReferenceExpression)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eUnset(int featureID)
  {
    switch (featureID)
    {
      case LanguagedefPackage.TAG_ENTRY_DEF__NAME:
        setName(NAME_EDEFAULT);
        return;
      case LanguagedefPackage.TAG_ENTRY_DEF__PARAMETERS:
        getParameters().clear();
        return;
      case LanguagedefPackage.TAG_ENTRY_DEF__TYPED_ENTRY:
        setTypedEntry(TYPED_ENTRY_EDEFAULT);
        return;
      case LanguagedefPackage.TAG_ENTRY_DEF__TYPE:
        setType(TYPE_EDEFAULT);
        return;
      case LanguagedefPackage.TAG_ENTRY_DEF__VALUE:
        setValue((XExpression)null);
        return;
      case LanguagedefPackage.TAG_ENTRY_DEF__REF:
        setRef((XReferenceExpression)null);
        return;
    }
    super.eUnset(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public boolean eIsSet(int featureID)
  {
    switch (featureID)
    {
      case LanguagedefPackage.TAG_ENTRY_DEF__NAME:
        return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
      case LanguagedefPackage.TAG_ENTRY_DEF__PARAMETERS:
        return parameters != null && !parameters.isEmpty();
      case LanguagedefPackage.TAG_ENTRY_DEF__TYPED_ENTRY:
        return typedEntry != TYPED_ENTRY_EDEFAULT;
      case LanguagedefPackage.TAG_ENTRY_DEF__TYPE:
        return TYPE_EDEFAULT == null ? type != null : !TYPE_EDEFAULT.equals(type);
      case LanguagedefPackage.TAG_ENTRY_DEF__VALUE:
        return value != null;
      case LanguagedefPackage.TAG_ENTRY_DEF__REF:
        return ref != null;
    }
    return super.eIsSet(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public String toString()
  {
    if (eIsProxy()) return super.toString();

    StringBuffer result = new StringBuffer(super.toString());
    result.append(" (name: ");
    result.append(name);
    result.append(", typedEntry: ");
    result.append(typedEntry);
    result.append(", type: ");
    result.append(type);
    result.append(')');
    return result.toString();
  }

} //TagEntryDefImpl
